<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas{
            /* border: 1px solid #ccc; */
            position: absolute;
            left: 20%;
        }
    </style>
</head>
<body>
    <canvas></canvas>
    <script>
        // 获取canvas
        let canvas = document.querySelector('canvas');
        canvas.width = 800;
        canvas.height = 400;
        // 获取绘图工具（获取画布上下文 画布的环境）
        let ctx = canvas.getContext('2d');
        // 直线 moveTo 开始的位置， lineTo 结束的位置
        ctx.moveTo(250, 100);
        ctx.lineTo(500, 100);
        // 设置宽度
        ctx.lineWidth = 4;
        // 设置颜色
        ctx.strokeStyle = 'red';
        // stroke 进行绘制
        ctx.stroke();
        // 开启新的路径
        ctx.beginPath();
        ctx.moveTo(380, 100);
        ctx.lineTo(380, 300);
        ctx.strokeStyle = 'skyblue';
        ctx.lineWidth = 4;
        ctx.lineCap = 'round';
        ctx.stroke();

        ctx.beginPath();
        ctx.moveTo(380, 200);
        ctx.lineTo(480, 200);
        ctx.strokeStyle = 'blue';
        ctx.lineWidth = 4;
        ctx.lineCap = 'round';
        ctx.stroke();

        ctx.beginPath();
        ctx.moveTo(260, 300);
        ctx.lineTo(500, 300);
        ctx.strokeStyle = '#67C23A';
        ctx.lineWidth = 4;
        ctx.lineCap = 'round';
        ctx.stroke();

        ctx.beginPath();
        ctx.moveTo(320, 200);
        ctx.lineTo(320, 300);
        ctx.strokeStyle = '#409EFF';
        ctx.lineWidth = 4;
        ctx.lineCap = 'round';
        ctx.stroke();
    </script>
</body>
</html>